<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js获取子节点索引</title>
  <style type="text/css">
    #test>li{
      width: 100px;
      height: 30px;
      background-color: red;
      margin: 10px 0;
    }
  </style>
</head>
<body>
  <!-- 
    点击每一个li标签打印出当前索引
  -->
  <ul id="test">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>

  <script>
    document.getElementById('test').addEventListener('click',function(e){
      const ndTarget  = e.target;
      const parentNodeChildren = Array.from(ndTarget.parentNode.children);
      // [].push.apply(parentNodeChildren,ndTarget.parentNode.children);
      console.log(parentNodeChildren.indexOf(ndTarget));
    })
  </script>
</body>
</html>